﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Reflection;
using CFSystem.JXC.AccessDAL;
using CFSystem.JXC.IDAL;

namespace CFSystem.JXC.DALFactory
{
    /// <summary>
    /// This class is implemented following the Abstract Factory pattern to create the DAL implementation
    /// specified from the configuration file
    /// </summary>
    public sealed class DataAccess
    {
        // Look up the DAL implementation we should be using
        private static readonly string path = System.Configuration.ConfigurationSettings.AppSettings["AccessDAL"];

        private DataAccess() { }
        
        public static CFSystem.JXC.IDAL.IBrand CreateBrand()
        {
            string className = path + ".Brand";
            return (CFSystem.JXC.IDAL.IBrand)Assembly.Load("AccessDAL").CreateInstance(className);
        }

        public static CFSystem.JXC.IDAL.IUnit  CreateUnit()
        {
            string className = path + ".Unit";
            return (CFSystem.JXC.IDAL.IUnit)Assembly.Load("AccessDAL").CreateInstance(className);
        }

        public static CFSystem.JXC.IDAL.IColor CreateColor()
        {
            string className = path + ".Color1";
            return (CFSystem.JXC.IDAL.IColor)Assembly.Load("AccessDAL").CreateInstance(className);
        }
        public static CFSystem.JXC.IDAL.ISize CreateSize()
        {
            string className = path + ".Size";
            return (CFSystem.JXC.IDAL.ISize)Assembly.Load("AccessDAL").CreateInstance(className);
        }

        public static CFSystem.JXC.IDAL.IProdCatergory CreateProdCatergory()
        {
            string className = path + ".ProdCatergory";
            return (CFSystem.JXC.IDAL.IProdCatergory)Assembly.Load("AccessDAL").CreateInstance(className);
        }

        public static CFSystem.JXC.IDAL.IProductDAL CreateProduct()
        {
            string className = path + ".ProductDAL";
            return (CFSystem.JXC.IDAL.IProductDAL)Assembly.Load("AccessDAL").CreateInstance(className);
        }

        public static CFSystem.JXC.IDAL.IVendor  CreateVendor()
        {
            string className = path + ".Vendor";
            return (CFSystem.JXC.IDAL.IVendor)Assembly.Load("AccessDAL").CreateInstance(className);
        }

        public static IStockDAL CreateStock()
        {
            string className = path + ".StockDAL";
            return (IStockDAL)Assembly.Load("AccessDAL").CreateInstance(className);
        }

        public static InvTransReasonSetting CreateInvTransReasonSetting()
        {
            string className = path + ".InTransReasonSetting";
            return (InvTransReasonSetting)Assembly.Load("AccessDAL").CreateInstance(className);
        }
        /// <summary>
        /// 库存信息查询
        /// </summary>
        /// <returns></returns>
        public static IStorageInfo  CreateStorageSearch()
        {
            string className = path + ".StorageInfoSearch";
            return (IStorageInfo)Assembly.Load("AccessDAL").CreateInstance(className);
        }
        /// <summary>
        /// 库存异动设置
        /// </summary>
        /// <returns></returns>
        public static ITransaction CreateInvTrans()
        {
            string className = path + ".InvTransaction";
            return (ITransaction)Assembly.Load("AccessDAL").CreateInstance(className);
        }
    }
}
